package com.shop.admin.controller;

import com.shop.admin.aop.Log;
import com.shop.admin.service.IPaperLogService;
import com.shop.admin.validate.PaperLogSearchValidate;
import com.shop.admin.validate.commons.IdValidate;
import com.shop.admin.validate.commons.PageValidate;
import com.shop.admin.vo.PaperLogDetailVo;
import com.shop.admin.vo.PaperLogListedVo;
import com.shop.common.core.AjaxResult;
import com.shop.common.core.PageResult;
import com.shop.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("${app.api-prefix}/log")
@Api(tags = "考试记录管理")
public class PaperLogController {

    @Resource
    IPaperLogService iPaperLogService;

    @GetMapping("/list")
    @ApiOperation(value="考试记录列表")
    public AjaxResult<PageResult<PaperLogListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated PaperLogSearchValidate searchValidate) {
        PageResult<PaperLogListedVo> list = iPaperLogService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="考试记录详情")
    public AjaxResult<PaperLogDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        PaperLogDetailVo detail = iPaperLogService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "考试记录删除")
    @PostMapping("/del")
    @ApiOperation(value="考试记录删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iPaperLogService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
